/**
 * \brief Class for generic players in KaoticSSB
 * Contains jump, movement and blink functionality
 * 	As well as collision logic
 */

using System;
using UnityEngine;
using System.Collections;

using KaoticSSB.Weapons;
using KaoticSSB.Globals;

namespace KaoticSSB.Players
{
	public class Player : PlayerBase
	{
		public Player ()
		{
		}

		public override void Init()
		{
			base.Init();
		}

		/**
		 * \brief Called once per frame
		 * Update respawn timer
		 * Check if player has fallen beneath the kill zone
		 * Handle input
		 */
		public override void Update()
		{
			base.Update();
			ProcessInput ();
		}

		#region INPUT
		/** 
		 * \brief Handles all input
		 * Check for movement, dodging, attacks
		 */
		public void ProcessInput()
		{
			GetLeftJoystickDirection();

			//right
			if(Input.GetAxis (Input_Horizontal) > 0)
			{
				this.gameObject.transform.Translate(MovementSpeed * Time.deltaTime, 0, 0);
			}
			//left
			if(Input.GetAxis (Input_Horizontal) < 0)
			{
				this.gameObject.transform.Translate(-MovementSpeed * Time.deltaTime, 0, 0);
			}

			//dodge
			if(DEBUG_TEXT_ENABLED)
			{
				Debug_Dodge();
			}
			if(Input.GetAxis(Input_Dodge) > 0)
			{
				if(mRightTriggerPressed == false && mCurrentBlinkCD <= 0)
				{
					PerformDodge();
				}
			}
			else
			{
				mRightTriggerPressed = false;
			}

			//throwing weapon
			if(Input.GetButtonDown("Throw_Weapon"))
		   	{
				ThrowWeapon ();
			}

			//melee weapon
			if(Input.GetButtonDown("Melee_Weapon"))
			{
				MeleeAttack ();
			}

			//jump
			if(Input.GetButtonDown (Input_Jump))
			{
				PerformJump();
			}
		}

		private void GetLeftJoystickDirection()
		{
			LeftJoystickDirection = new Vector2(Input.GetAxis (Input_Horizontal), -1 * Input.GetAxis (Input_Vertical));
		}
		#endregion
	}
}

